<?php
/*
* Timer class
* We wrote this, but felt it was too simple to license.
* So do whatever you want with this class, no need to credit us.
*/
class timer {
	var $startTime = false;
	
	function timer() {
		$this->start();
	}
	
	function restart() {
		$this->clear();
		$this->start();
	}
	
	function start() {
		if($this->startTime!==false)
			trigger_error('The timer has already been started',E_USER_ERROR);
		
		$this->startTime=$this->microtime_float();
	}
	
	function clear() {
		if($this->startTime===false)
			trigger_error('The timer has not yet been started',E_USER_ERROR);
		
		$this->startTime=false;
		$this->elapsed=false;
	}
	
	function getElapsed() {
		if($this->startTime===false)
			trigger_error('The timer has not yet been started',E_USER_ERROR);
		
		return $this->microtime_float()-$this->startTime;
	}
	
	function microtime_float() {
	    list($usec, $sec) = explode(" ", microtime());
		return ((float)$usec + (float)$sec);
	}
}
?>